<?php


namespace App\Services;

use App\DTOS\Admin\AdminDTO;
use App\Models\Admin;

class AdminService
{
    /**
     * @param AdminDTO $adminDTO
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function paginate(AdminDTO $adminDTO){
        $username = $adminDTO->getUsername();
        $page = $adminDTO->getPage();
        $pageSize = $adminDTO->getLimit();
        $model = Admin::query()->with('roles');
        if ($username){
            $model->where('username','like',"%$username%");
        }
        return $model->paginate($pageSize,'*','page',$page);
    }

}
